package 笔试.笔试360;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

/**
 * @author:谢君臣
 * @Date:2021/10/24-15:15
 * @version:1.0
 * @function:
 * 1
 * 4 4
 * 3 0 5 6
 * 0 9 1 4
 * 1 8 1 1
 * 4 -1 5 -1
 */
public class Man {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        while (n > 0) {
            int x = scanner.nextInt(), y = scanner.nextInt();
            int[][] arr = new int[x][y];
            int max = -1;
            for (int i = 0; i < x; i++){
                for (int j = 0; j < y; j++) {
                    arr[i][j] = scanner.nextInt();
                    max = Math.max(max, arr[i][j]);
                }
            }
            if (max<0){
                System.out.println(-1);
                break;
            }
            for (int i = 0; i < x; i++) {
                for (int j = 0; j < y; j++) {
                    for (int length = 1; i + length < x && j + length < y; length++) { // 矩阵长度
                        int sum = 0;
                        for (int k_x = i; k_x <= i+length; k_x++) {
                            boolean flag=true;
                            for (int k_y = j; k_y <=j+length ; k_y++) {
                                if (arr[k_x][k_y]<0){
                                    flag = false;
                                    break;
                                }else {
                                    sum+=arr[k_x][k_y];
                                }
                            }
                            if (!flag){
                                sum=0;
                                break;
                            }
                        }
                        max = Math.max(max,sum);
                    }
                }
            }
            System.out.println(max);
            n--;
        }
    }
}
